//
//  UIImage+Stretch.m
//  CommentCell
//
//  Created by power on 2017/6/5.
//  Copyright © 2017年 powertorque. All rights reserved.
//

#import "UIImage+Stretch.h"

@implementation UIImage (Stretch)

/** 返回一张能够自由拉伸的图片 */
+ (UIImage *)bs_resizedImageWithImageStr:(NSString *)imageStr withLeft:(CGFloat)left andTop:(CGFloat)top
{
    UIImage *image = [UIImage imageNamed:imageStr];
    return [self resizedImageWithImage:image withLeft:left andTop:top];
}
+ (UIImage *)bs_resizedImageWithImage:(UIImage *)image withLeft:(CGFloat)left andTop:(CGFloat)top
{
    return [image stretchableImageWithLeftCapWidth:image.size.width * left topCapHeight:image.size.height * top];
}
+ (UIImage *)bs_resizedImageWithImageStr:(NSString *)imageStr
{
    return [self bs_resizedImageWithImageStr:imageStr withLeft:0.5 andTop:0.5];
}
+ (UIImage *)bs_resizedImageWithImage:(UIImage *)image
{
    return [self bs_resizedImageWithImage:image withLeft:0.5 andTop:0.5];
}


@end


@implementation UIImage (Combine)

/** 根据颜色返回一张图片 */
+ (UIImage *)bs_imageWithColor:(UIColor *)color alpha:(CGFloat)alpha
{
    CGRect rect = CGRectMake(0, 0, 1, 1);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(ctx, color.CGColor);
    CGContextSetAlpha(ctx, alpha);
    CGContextAddRect(ctx, rect);
    CGContextFillPath(ctx);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}
+ (UIImage *)bs_imageWithRGBColorRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha
{
    CGRect rect = CGRectMake(0, 0, 1, 1);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextSetRGBFillColor(ctx, red, green, blue, alpha);
    CGContextAddRect(ctx, rect);
    CGContextFillPath(ctx);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}
+ (UIImage *)bs_imageWithColor:(UIColor *)color size:(CGSize)size alpha:(CGFloat)alpha
{
    CGRect rect = CGRectMake(0, 0, size.width, size.height);
    UIGraphicsBeginImageContext(size);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(ctx, color.CGColor);
    CGContextSetAlpha(ctx, alpha);
    CGContextAddRect(ctx, rect);
    CGContextFillPath(ctx);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}



@end
